﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace Klinkby.MicroBus
{
    /// <summary>
    /// Implements a basic <see cref="IMessage"/>
    /// </summary>
    [DataContract, Serializable]
    public class Message : MarshalByRefObject, IMessage
    {
        readonly string _topic;
        readonly string _sender;
        readonly byte[] _payload;

        [DebuggerStepThrough]
        public Message(string topic, string sender, byte[] payload)
        {
            _topic = Safe.NonNull(topic, "topic");
            _sender = Safe.NonNull(sender, "sender");
            _payload = Safe.NonNull(payload, "payload");
        }
        #region IMessage Members

        /// <summary>
        /// Message topic
        /// </summary>
        public string Topic
        {
            [DebuggerStepThrough]
            get
            {
                return _topic;
            }
        }

        /// <summary>
        /// Message data contents
        /// </summary>
        public byte[] Payload
        {
            [DebuggerStepThrough]
            get
            {
                return _payload;
            }
        }

        /// <summary>
        /// Message origin
        /// </summary>
        public string Sender
        {
            [DebuggerStepThrough]
            get
            {
                return _sender;
            }
        }

        #endregion
    }
}
